<!DOCTYPE html>
<html xmlns:th="www.thymeleaf.org">
<head th:replace="header::head"></head>
<title>修改信息 - 个人中心 - 双辞动漫-专注二次元动漫的小站</title>
<meta name="keywords" content="修改信息 - 个人中心">
<meta name="description" content="修改信息 - 个人中心">
<script type="text/javascript" src="/template/conch/asset/js/set/formValidator.js"></script>
<script type="text/javascript" src="/static/js/jquery.imageupload.js"></script>
<script type="text/javascript">
    var maccms={"path":"","mid":"6","url":"www.scdmfun.cn","wapurl":"www.cdmfun.cn","mob_status":"0"};
    var conchtpl={"surl":"/search.html","tipt":"网站公告","tipc":"这里是双辞动漫新站<br><span class='hl-text-conch'>注意事项：</span>1.老站新老站账号不通用<br>老站网址：<span class='hl-text-conch'>dm.scdmfun.cn</span><br>2.如果登录后还是提示未登录请稍等一会再刷新即可<br>动漫闲聊群：<span class='hl-text-conch'>542266218</span>","slink":"https://www.scdmfun.cn/","short":"","api":"0","tok":"","term":"long-term","ver":"3.1"}
</script>
<body id="conch-member">
<!--海螺影视主题  https://www.360mb.net/23977.html-->
<div th:replace="header::.conch-header"></div>
<div class="conch-header">
    <div class="conch-headwrap conch-hasone conch-hasconch hl-hide-sm">
        <div class="hl-mob-nav">
            <a href="javascript:MAC.GoBack()" class="hl-pull-left left"><i class="iconfont hl-icon-jiantouzuo"></i></a>
            <a href="javascript:void(0)" class="hl-pull-right right"></a>
            <span class="hl-mob-title hl-text-site hl-lc-1">修改信息</span>
        </div>
    </div>
</div>
<div id="info" class="conch-content conch-member">
    <div class="conch-ctwrap">
        <div class="hl-ctwrap-item">
            <div class="container">
                <div class="hl-row-box clearfix">
                    <div class="row">
                        <div th:replace="ajax_info::#left"></div>
                        <div id="right" class="hl-right-content hl-col-xs-12 hl-col-sm-70w hl-col-lg-9">
                            <div class="hl-cont-right">
                                <div class="hl-rb-head hl-hidden-xs clearfix">
                                    <h2 class="hl-rb-title">我的资料</h2>
                                </div>
                                <div class="hl-cont-tab">
                                    <div th:replace="ajax_info::#info_common"></div>
                                    <div id="hl-cont-list" class="hl-cont-list">
                                        <div class="hl-list-wrap">
                                            <p><span>用户名</span><input type="text" name="user_ucount" placeholder="请输入账号" v-model="messsage.ucount"></p>
                                            <p><span>昵称</span><input type="text" name="user_nick_name" placeholder="请输入昵称" v-model="messsage.nickname1"></p>
                                            <p><span>QQ号码</span><input type="text" name="user_qq" placeholder="请输入QQ号" v-model="messsage.qq"></p>
                                            <p v-show="mailFlag"><span>邮箱</span><input type="text" name="user_email" readonly="readonly" class="hl-input-w3" v-model="messsage.email">
                                                <a class="hl-text-conch btn_unbind" ac="email" href="javascript:;" title="解绑邮箱" @click="modifyemail()" v-text="messsage.email == '' ? '绑定' : '解绑'"></a></p>
                                            <p v-show="emailFlag"><span>请输入邮箱</span><input type="text" name="user_email" class="hl-input-w3" v-model="messsage.otheremail">
                                                <a class="hl-text-conch btn_unbind" ac="email" href="javascript:;" title="绑定邮箱" @click="getMailCode()">获取验证码</a></p>
                                            <p v-show="magFlag"><span></span><input type="text" name="user_phone" placeholder="邮箱格式不正确,请从新绑定" readonly="readonly"></p>
                                            <p v-show="msgFlag"><span>验证码</span><input type="text" name="user_code" class="hl-input-w3" value="" placeholder="请输入验证码" v-model="messsage.mailcode">
                                                <a class="hl-text-conch btn_unbind" ac="email" href="javascript:;" @click="removemail()">确定</a></p>
                                            <p><span>手机</span><input type="text" name="user_phone" placeholder="请输入手机号" v-model="messsage.phone"></p>
                                            <p><span>密保问题</span><input type="text" name="user_question" value="" placeholder="请输入找回密码问题" v-model="messsage.question"></p>
                                            <p><span>密保答案</span><input type="text" name="user_answer" value="" placeholder="请输入找回密码答案" v-model="messsage.answer"></p>
                                            <input type="button" id="btn_submit" class="hl-btn-submit hl-bg-conch" value="保存" @click="modify()">
                                            <div class="hl-tip-text"><a href="/findpass.html">忘记密码了？找回密码</a></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--海螺影视主题  https://www.360mb.net/23977.html-->
<div th:replace="ajax_info::.conch-footer"></div>
<script src="https://lib.baomitu.com/vue/2.6.14/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.26.0/axios.min.js"></script>
<script type="text/javascript">
    new Vue({
        el: "#info",
        data() {
            return {
                messsage: {
                    ucount: '',  //账号
                    nickname: '',  //昵称
                    uscore: '',   //积分
                    password: '',  //密码
                    email: '',    //邮箱
                    qq: '',       //QQ
                    registerdata: '',  //注册时间
                    lastlogineddate: '',  //最后登录时间
                    curlogindate: '',    //当前登录时间
                    ugroup: '',         //会员类型
                    deadline: '',       //会员期限
                    loginednum: '',      //登录次数
                    question: '',    //密保
                    answer: '',        //答案
                    phone: '',          //手机
                    mailcode: '',      //邮箱验证码
                    otheremail: '',
                    nickname1: ''
                },
                msgFlag:false,        //判断解绑时是否弹出
                magFlag:false,        //判断输入邮箱的格式是否正确，错误时弹出
                emailFlag:false,       //判断是否需要输入邮箱时而弹出
                mailFlag:true         //判断绑定和解绑的窗口是否弹出
            }
        },
        computed:{},
        created(){
            // this.init()
        },
        mounted(){
            window.selectinfo = this.selectinfo();
        },
        methods: {
            usermodify(data) {
                return axios({
                    'url': '/user/modify',
                    'method': 'put',
                    data
                })
            },
            modifyemail(){
                if (this.messsage.email != ''){
                    this.getMailCode()
                    this.msgFlag=true
                    this.mailFlag=false
                }else{
                    this.emailFlag=true
                    this.mailFlag=false
                }
            },

            selectinfo(){
                let url = "user/selectuser";
                axios.post(url).then(res=>{
                    var data= res.data;
                    if (data.code==1){
                        this.messsage=data.data;
                        this.messsage.nickname1 = this.messsage.nickname;
                    }
                })
            },
            modify(){
                if(this.messsage.ucount && this.messsage.email){
                    this.messsage.nickname = this.messsage.nickname1;
                    this.usermodify(this.messsage).then(res=>{
                        alert(res.data.msg);
                    })
                }else{
                    alert("输入错误");
                }

            },
            getMailCode(){
                const regex = /^([A-z0-9]{6,18})(\w|\-)+@[A-z0-9]+\.([A-z]{2,3})$/;
                if (this.messsage.email == '' && this.messsage.otheremail != null){
                    this.messsage.email = this.messsage.otheremail
                }else{
                    this.messsage.email = this.messsage.email
                }
                if(regex.test(this.messsage.email)) {
                    this.magFlag=false
                    this.msgFlag=true
                    let url = "/user/sendmail";
                    let params = new URLSearchParams();
                    params.append("email", this.messsage.email);
                    axios.post(url, params).then(res => {
                        if (res.data.code == 1) {
                            alert(res.data.msg);
                        }
                    })
                }else{
                    this.magFlag=true
                }
            },
            removemail(){
                if (this.messsage.mailcode){
                    let url = "/user/removemail";
                    let params = new URLSearchParams();
                    if (this.emailFlag==false){
                        this.messsage.email=''
                    }
                    params.append("email",this.messsage.email);
                    params.append("ucount",this.messsage.ucount);
                    params.append("mailcode",this.messsage.mailcode);
                    axios.put(url,params).then(res=>{
                        if(res.data.code==1){
                            this.msgFlag = false
                            alert(res.data.msg);
                            this.mailFlag=true
                            this.emailFlag=false
                            this.selectinfo()
                        }else{
                            alert(res.data.msg)
                        }
                    })
                }else{
                    alert("请输入正确的验证码");
                }
            },
            setTime(){
                onload=function(){
                    setInterval(go, 1000);
                };
                var x=3; //利用了全局变量来执行
                function go(){
                    x--;
                    if(x>0){
                        alert(x);  //每次设置的x的值都不一样了。
                    }else{
                        location.href='info.html';
                    }
                }
            },
            handleFile(){
                let files = document.getElementById('file').files;
                if(!files){
                    return;
                }
                this.file=files[0];
                this.uploadFile();
            },
            uploadFile(){
                let formData = new FormData();
                formData.append("file",this.file);
                formData.append("uid",this.messsage.uid);
                axios({
                    url:'/uploadFile',
                    method:'post',
                    data:formData
                }).then(res=>{
                    if(res.data.code > 0 ){
                        this.selectuser();
                        login.$data.user={};
                    }
                })
            }
        }
    });
</script>
</body>
</html>